package baseAPI;

import javafx.animation.*;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.effect.Glow;
import javafx.scene.effect.Lighting;
import javafx.scene.layout.Pane;
import javafx.scene.text.Text;
import javafx.scene.transform.Scale;
import javafx.util.Duration;
import javafx.scene.shape.*;

import java.awt.*;

public class Animation {
    private static Pane pane;//用于添加图形

    public static void setPane(Pane pane){//设置布局
        Animation.pane = pane;
    }

    public static void fadeIn(Node node){//淡入和移动
        FadeTransition f = new FadeTransition(Duration.millis(500));//淡入效果
        TranslateTransition t = new TranslateTransition(Duration.millis(200));//移动效果

        f.setFromValue(0);
        f.setToValue(1);
        f.setNode(node);

        t.setFromY(30);
        t.setToY(0);
        t.setNode(node);

        (new ParallelTransition(f, t)).play();
    }

    public static void fadeInRight(Node node){//淡入和移动
        FadeTransition f = new FadeTransition(Duration.millis(500));//淡入效果
        TranslateTransition t = new TranslateTransition(Duration.millis(200));//移动效果

        f.setFromValue(0.5);
        f.setToValue(1);
        f.setNode(node);

        t.setFromX(0);
        t.setToX(25);
        t.setNode(node);

        (new ParallelTransition(f, t)).play();
    }

    public static void fadeInLeft(Node node){//淡入和移动
        FadeTransition f = new FadeTransition(Duration.millis(500));//淡入效果
        TranslateTransition t = new TranslateTransition(Duration.millis(200));//移动效果

        f.setFromValue(0);
        f.setToValue(1);
        f.setNode(node);

        t.setFromX(0);
        t.setToX(-95);
        t.setNode(node);

        (new ParallelTransition(f, t)).play();
    }

    public static void fadeOut(Node node){//淡出和移动
        FadeTransition f = new FadeTransition(Duration.millis(500));//淡入效果
        TranslateTransition t = new TranslateTransition(Duration.millis(200));//移动效果

        f.setFromValue(1);
        f.setToValue(0);
        f.setNode(node);

        t.setFromY(30);
        t.setToY(0);
        t.setNode(node);

        (new ParallelTransition(f, t)).play();
    }

    public static void show(Node node){//放大出现
        ScaleTransition s = new ScaleTransition(Duration.millis(500), node);
        s.setFromX(0);
        s.setFromY(0);
        s.setToX(1);
        s.setToY(1);

        FadeTransition f = new FadeTransition(Duration.millis(700), node);
        f.setFromValue(0);
        f.setToValue(1);

        ParallelTransition p = new ParallelTransition(s, f);

        p.play();
    }

    public static void disappear(Node node){//缩小消失
        FadeTransition f = new FadeTransition(Duration.millis(500));//淡入效果
        f.setFromValue(1);
        f.setToValue(0);

        ScaleTransition s = new ScaleTransition(Duration.millis(500), node);
        s.setToX(0);
        s.setToY(0);

        ParallelTransition p = new ParallelTransition(f, s);
        p.play();
    }

    public static void reset(Node node){
        TranslateTransition t = new TranslateTransition(Duration.millis(200));//复原移动
        t.setFromY(0);
        t.setToY(0);
        t.setFromX(-80);
        t.setToX(0);
        t.setNode(node);
        node.setEffect(null);
        t.play();
    }

    public static void reset1(Node node){
        TranslateTransition t = new TranslateTransition(Duration.millis(200));//复原移动
        t.setFromX(10);
        t.setToX(0);
        t.setNode(node);
        t.play();
    }

    public static void checked(Node node){
        TranslateTransition t = new TranslateTransition(Duration.millis(200));//复原移动
        t.setFromX(0);
        t.setToX(10);
        t.setNode(node);
        t.play();
    }

    public static void resetCheck(Node node){
        node.setEffect(null);
    }

    public static void checkButton(Node node)
    {
        Glow glow = new Glow();
        glow.setLevel(15);
        node.setEffect(glow);
    }
}
